
<template>
  <el-dialog :close-on-click-modal="false" @close="hide" :title="$tt('label_file_upload')" :visible.sync="visible" custom-class="dialog_mini">

    <ex-upload-file ref="fileUpload" v-model="files" type="upload-file" key="attachedDTOList"
      multiple :limit="5" drag accept='.xls,.xlsx,.doc,.docx,.rar,.zip'
      @input="fileUploadChange"
      @handleRemove = 'handleRemove'
      >
      <i class="el-icon-upload"></i>
      <div class="el-upload__text" v-html="$tt('tip_upload_attachment_drag_click')"></div>
    </ex-upload-file>
    <span slot="footer" class="dialog_footer">
      <el-button @click="hide">{{ $tt('label_cancel') }}</el-button>
      <el-button type="primary" @click="submit">{{ $tt('label_submit') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {

  data() {
    return {
      visible: false,

      loading: false,
      files:[],
      waybillId:null

    }
  },
  methods: {
    show(item) {
      this.visible = true
      this.waybillId = item.id
      this.getFile(item.id)
    },
    getFile(waybillId){
      this.$ajax({
        url: "/tms-api/waybill/TmsWaybillInfoFileRpc/selectAll.json",
        method: 'get',
        loading: true,
        data: {
          waybillId
        },
        success: (res) => {
          res.data.rows.forEach(item=>{
            this.files.push({
              fileName:item.fileName,
              filePath:item.fileUrl
            })
          })
          console.log('查询文件',this.files)
        },
      })
    },
    fileUploadChange(flies) {
      console.log(flies)
    },
    handleRemove(file, fileList) {
        console.log(file, fileList);
      },
    hide() {
      this.visible = false
      this.files = []
      this.waybillId = null
    },
    submit() {
      const waybillInfoFileList = []
      this.files.forEach(item=>{
        waybillInfoFileList.push({
          fileUrl:item.filePath,
          fileName:item.fileName
        })
      })
      this.$ajax({
        url: "/tms-api/waybill/TmsWaybillInfoFileRpc/addWaybillInfoFile.json",
        method: 'post', type: 'json',
        loading: true,
        data: {
          waybillId: this.waybillId,
          waybillInfoFileList
        },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.hide()
          this.$emit('submitSuccess')
        },
      })
    },

  }
}
</script>
